<?php $this->headLink()->appendStylesheet($this->baseUrl() . '/css/offer.css') ?>
<?php
$isAddMode = false;
$imageRouting = 'image';
$token = null;
if (isset($this->addMode) && $this->addMode) {
    $isAddMode = true;
    $imageRouting = 'offerImage';
    $token = $this->token;
}
?>
<div class="offer span12">
    <div class="clearfix breadcrumb-categories">
        Kategoria: 
        <a href="<?= $this->url(array('controller' => 'offer', 'action' => 'index', 'id' => $this->offer['parent_category_code'], 'name' => $this->offer['parent_category_name']), 'default', true) ?>"><?= $this->offer['parent_category_name'] ?></a>
        <i class="icon-chevron-right"></i> 
        <a href="<?= $this->url(array('controller' => 'offer', 'action' => 'index', 'id' => $this->offer['category_code'], 'name' => $this->offer['category_name']), 'default', true) ?>"><?= $this->offer['category_name'] ?></a>
    </div>
    <div class="navbar">
        <div class="navbar-inner">
            <?php if(isset($this->offer['creation_date'])): ?>
            <div class="item_date" title="Data dodania ogłoszenia"><?php $tmp = explode(' ', $this->offer['creation_date']); echo $tmp[0]; ?></div>
            <?php endif; ?>
            <h3 class="title"><?= $this->escape($this->offer['title']) ?></h3>
        </div>
    </div>
    <div class="clearfix">
        <?php if (!empty($this->offer['image_code'])): ?>
            <div class="thumbnails pull-right thumb-prev">
                <a class="thumbnail imagePreview" href="<?= $this->url(array('id' => $this->offer['image_code'], 'width' => 800, 'height' => 800, 'token' => $token), $imageRouting, true) ?>">
                    <img src="<?= $this->url(array('id' => $this->offer['image_code'], 'width' => 200, 'height' => 200, 'token' => $token), $imageRouting, true) ?>" alt="" />
                </a>
            </div>
        <?php endif ?>
        <div class="body"><?= nl2br($this->offer['content']) ?></div>
    </div>
    <?php if (!empty($this->offer['attributes'])): ?>
        <fieldset>
            <legend><?= $this->translate('XXX_OFFER_SHOW_ADDITIONAL_INFO') ?></legend>
            <?php
            $tagStart = '<div class="row-fluid offer_attributes">';
            $tagEnd = '</div>';
            $it = 0;
            ?>

            <?php foreach ($this->offer['attributes'] as $attr): ?>
                <?php
                if ($attr['size'] == 'small'):
                    if ($it == 0) {
                        echo $tagStart;
                    } elseif ($it == 2) {
                        echo $tagEnd . $tagStart;
                    }
                    $it++;
                    ?>
                    <div class="span3 attr_name"><?= $attr['display_pl'] ?></div>
                    <div class="span3 attr_value"><?= $this->escape($attr['value']) ?></div>
                    <?php
                else:
                    ?>
                    <?php
                    if ($it != 0) {
                        echo $tagEnd;
                    }
                    echo $tagStart;
                    $it = 0;
                    ?>
                    <div class="span3 attr_name"><?= $attr['display_pl'] ?></div>
                    <div class="span9 attr_value"><?= nl2br($this->escape($attr['value'])) ?></div>
                    <?php echo $tagEnd; ?>
                <?php
                endif;
            endforeach;
            if ($it != 0) {
                echo $tagEnd;
            }
            ?>
        </fieldset>
    <?php endif ?>
    <?php if (!empty($this->offer['images']) && count($this->offer['images']) > 1): ?>
        <div class="row-fluid offer_imgs">
            <div class="thumbnails">
                <?php foreach ($this->offer['images'] as $img): ?>
                    <?php
                    if ($img['code'] == $this->offer['image_code'])
                        continue;
                    ?>
                    <a class="thumbnail span3 imagePreview" href="<?= $this->url(array('id' => $img['code'], 'width' => 800, 'height' => 800, 'token' => $token), $imageRouting, true) ?>">
                        <img src="<?= $this->url(array('id' => $img['code'], 'width' => 200, 'height' => 200, 'token' => $token), $imageRouting, true) ?>" alt="" />
                    </a>
    <?php endforeach; ?>
            </div>
        </div>
<?php endif ?>
    <fieldset>
        <legend><?= $this->translate('XXX_OFFER_SHOW_CONTACT_SECTION') ?></legend>
        <div class="row-fluid offer_attributes">                    
            <div class="span3 attr_name"><?= $this->translate('XXX_OFFER_SHOW_CONTACT_NAME_LABEL') ?></div>
            <div class="span3 attr_value"><?= $this->offer['contact_name'] ?></div>
            <div class="span3 attr_name"><?= $this->translate('XXX_OFFER_SHOW_CONTACT_PHONE_LABEL') ?></div>
            <div class="span3 attr_value"><?= $this->offer['contact_phone'] ?></div>
        </div>
<?php if (!empty($this->offer['contact_email']) && $this->offer['contact_email_visible_flag']): ?>
            <div class="row-fluid offer_attributes">                    
                <div class="span3 attr_name"><?= $this->translate('XXX_OFFER_SHOW_CONTACT_EMAIL_LABEL') ?></div>
                <div class="span9 attr_value"><?= $this->offer['contact_email'] ?></div>
            </div>
        <?php endif ?>
<?php if (!empty($this->offer['contact_skype']) || !empty($this->offer['contact_gg'])): ?>
            <div class="row-fluid offer_attributes">                    
                <div class="span3 attr_name"><?= $this->translate('XXX_OFFER_SHOW_CONTACT_SKYPE_LABEL') ?></div>
                <div class="span3 attr_value"><?= $this->offer['contact_skype'] ?></div>
                <div class="span3 attr_name"><?= $this->translate('XXX_OFFER_SHOW_CONTACT_GG_LABEL') ?></div>
                <div class="span3 attr_value"><?= $this->offer['contact_gg'] ?></div>
            </div>
    <?php endif ?>
    </fieldset>
<?php if (isset($this->similars) && !empty($this->similars)): ?>
        <div class="similars offer_list small">
            <div class="title"> Podobne ogłoszenia z tej kategorii: </div>
            <div class="thumbnails">
                <?php foreach ($this->similars as $i => $entry): ?>
                    <?php
                    $url = $this->url(array('controller' => 'offer', 'action' => 'show', 'id' => $entry['code'], 'title' => $entry['title']), 'default', true);
                    ?>
                    <div class="media offer_row thumbnail offer-type-<?= $entry['type'] ?>">
                        <div class="pull-left">
                            <a class="img_prev" style="background-image: url(<?= $this->url(array('id' => empty($entry['image_code']) ? 0 : $entry['image_code'], 'width' => 40, 'height' => 40), 'image', true) ?>);" href="<?= $url ?>">&nbsp;</a>
                        </div>
                        <div class="media-body">
                            <h3 class="media-heading"><a href="<?= $url ?>"><?= $this->escape($entry['title']) ?></a></h3>
                            <div class="desc">
                                <?php
                                $filter = new Zend_Filter_StripTags();
                                $text = $filter->filter($entry['intro']);
                                $text = wordwrap($text, 200, '#&|&#');
                                $text = explode('#&|&#', $text);
                                if (count($text) > 1) {
                                    $text = $text[0] . '...';
                                } else {
                                    $text = $text[0];
                                }
                                echo $text;
                                ?>
                            </div>
                        </div>
                    </div>
    <?php endforeach ?>
            </div>
        </div>
<?php endif; ?>
</div>
